home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 551-575 / disk_560 / stscan / stscan.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  43KB  |  2,261 lines

  1. /* ST-400 Scanner Programm */
  2. #include <exec/exec.h>
  3. #include <exec/types.h>
  4. #include <intuition/intuition.h>
  5. #include <intuition/intuitionbase.h>
  6. #include <libraries/dos.h>
  7. #include <libraries/dosextens.h>
  8. #include <graphics/rastport.h>
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <functions.h>
  12.  
  13. #define ST400ID 3
  14. #define ST400LUN 96
  15. #define DEV_NAME (char*)"scsi.device" /* <- change for other SCSI controller */
  16. #define FORM 0x464f524d
  17. #define ILBM 0x494c424d
  18. #define BMHD 0x424d4844
  19. #define BODY 0x424f4459
  20. #define DIR_READ  1
  21. #define DIR_WRITE 0
  22.  
  23. struct MsgPort *HCPort;
  24. struct IntuitionBase *IntuitionBase;
  25. struct GfxBase *GfxBase;
  26. struct DosBase *DosBase;
  27. struct IntuiMessage *Message;
  28. struct Window *win;
  29. struct Screen *scr;
  30. struct Viewport *vp;
  31. struct RastPort *rp;
  32. struct MsgPort *diskport;
  33. struct IOStdReq *diskreq;
  34. ULONG MessageClass;
  35. USHORT Code;
  36. long openerror;
  37. ULONG memneed=0;
  38. UWORD memwidth, memheight;
  39. UBYTE memgray;
  40. UBYTE *memptr;
  41. USHORT *imgptrf, *imgptrz;
  42.  
  43. UBYTE numbits_16[]={0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4};
  44. UBYTE numbits[256];
  45. UBYTE graystep[]={0,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1};
  46. UBYTE bitval[]={128,64,32,16,8,4,2,1};
  47. UBYTE invbitval[]={127,191,223,239,247,251,253,254};
  48. UBYTE sk,mf;
  49. UWORD vx,vy,wx1,wy1,wx2,wy2;
  50.  
  51. /* Variables for Heath File Requester */
  52. char *str_filenam[100];
  53. char *str_cmdline[110];
  54. char *def_name[50] = "";
  55. char *def_dir[50] = "";
  56.  
  57.  
  58. /* Interface Viariables for Assembly Routines */
  59. volatile UBYTE *p0,*p1,*p2,*p3,*p4;
  60. volatile UWORD cnt;
  61. volatile ULONG v1;
  62.  
  63. typedef struct DefWindow /*might be scanner dependent*/
  64. {  ULONG dummy1;
  65.    UWORD dummy2;
  66.    UWORD wpsize;
  67.    UBYTE winnr;
  68.    UBYTE dummy3;
  69.    UWORD resx;
  70.    UWORD resy;
  71.    UWORD cornerx;
  72.    UWORD cornery;
  73.    UWORD width;
  74.    UWORD height;
  75.    UBYTE dummy4;
  76.    UBYTE threshold;
  77.    UBYTE size;     /* temporary storage, ignored by scanner */
  78.    UBYTE halftone;
  79.    UBYTE bitspixel;
  80.    UBYTE dummy5;
  81.    UWORD dummy6;
  82.    ULONG dummy7;
  83. };
  84.  
  85. typedef struct SCSICmd  /* included here because */
  86. {   UWORD  *scsi_Data;    /* header file missing in Aztec C 5.0 */    
  87.     ULONG   scsi_Length;    
  88.     ULONG   scsi_Actual;    
  89.     UBYTE  *scsi_Command;    
  90.     UWORD   scsi_CmdLength;    
  91.     UWORD   scsi_CmdActual;    
  92.     UBYTE   scsi_Flags;        
  93.     UBYTE   scsi_Status;    
  94. };
  95.  
  96.  
  97. struct DefWindow winpar= /*default values */
  98. {  0,0,32,    /*dummy1, dummy2, wpsize*/
  99.    1,0,        /*winnr, dummy3*/
  100.    200,200,    /*resx, resy*/
  101.    0,0,0,0,    /*cornerx, cornery, width, height*/
  102.    0,32,5,    /*dummy4, threshold, size*/
  103.    0,1,        /*halftone, bitspixel*/
  104.    0,0,0    /*dummy5,6,7*/
  105. };
  106.  
  107. /* Scanner specific sizes and commands */
  108.  
  109. UWORD cornerxval[]={  22,  33,  44, 266, 399, 535};
  110. UWORD corneryval[]={   6,   6,   6,   6,   6,   6};
  111. UWORD widthval[]=  {1164,2496,3312,1168,1760,2336};
  112. UWORD heightval[]= {2336,3504,4672,1656,2484,3312};
  113.  
  114. UBYTE cmd_scan[]={0x1b,ST400LUN,0,0,0,0};
  115. UBYTE cmd_read[]={0x28,ST400LUN,0,0,0,0,0,0,0,0};
  116. UBYTE cmd_dwin[]={0x24,ST400LUN,0,0,0,0,0,0,40,0};
  117. UBYTE cmd_mdon[]={0x15,ST400LUN,0,0,0,128};
  118. UBYTE cmd_mdoff[]={0x15,ST400LUN,0,0,0,0};
  119. UBYTE cmd_inqu[]={0x12,ST400LUN,0,0,96,0};
  120.  
  121.  
  122. int prefdatei,sdatei,qdatei,wdatei;
  123. unsigned int i;  
  124. unsigned int len;
  125. unsigned char a;
  126.  
  127. /* IFF-ILBM Constants */
  128.  
  129. UBYTE iff_cmap_bw[]=
  130. {'C','M','A','P',0,0,0,6,0,0,0,255,255,255};
  131.  
  132. UBYTE iff_cmap_gray[]=
  133. {'C','M','A','P',0,0,0,48,0,0,0,16,16,16,32,32,32,48,48,48,64,64,64,80,80,80,
  134.  96,96,96,112,112,112,128,128,128,144,144,144,160,160,160,176,176,176,
  135.  192,192,192,208,208,208,224,224,224,240,240,240};
  136.  
  137. ULONG iff_head[]={FORM,0,ILBM,BMHD,20,0,0,0,0x00000101,0x02800200};
  138.  
  139. ULONG iff_body[]={BODY,0};
  140.  
  141.  
  142. /* Struktures for Windows and Menus */
  143.  
  144. struct TextAttr textattr=
  145. { "topaz.FONT",
  146.    8,
  147.    FS_NORMAL,
  148.    FPF_ROMFONT
  149. };
  150.  
  151. /* Struktures for Gadgets */
  152.  
  153. USHORT zvect2[]={0,0, 0,12, 12,12, 12,0, 0,0,
  154.                 -1,-1, -1,11, 11,11, 11,-1, -1,-1};
  155. USHORT zvect1[]={0,0, 0,10, 10,10, 10,0, 0,0};
  156.  
  157. USHORT imagedataf[]=
  158. { 0xfff0,
  159.   0xfff0,
  160.   0xc030,
  161.   0xdff0,
  162.   0xdff0,
  163.   0xc0f0,
  164.   0xdff0,
  165.   0xdff0,
  166.   0xdff0,
  167.   0xdff0,
  168.   0xfff0,
  169.   0xfff0,
  170.   0x0000,
  171.   0x0000,
  172.   0x0000,
  173.   0x0000,
  174.   0x0000,
  175.   0x0000,
  176.   0x0000,
  177.   0x0000,
  178.   0x0000,
  179.   0x0000,
  180.   0x0000,
  181.   0x0000,
  182.   0x0000,
  183.   0x0000,
  184.   0x0000,
  185.   0x0000,
  186.   0x0000,
  187.   0x0000,
  188.   0x0000,
  189.   0x0000,
  190.   0x0000,
  191.   0x0000,
  192.   0x0000,
  193.   0x0000,
  194.   0x0000,
  195.   0x0000,
  196.   0x0000,
  197.   0x0000,
  198.   0x0000,
  199.   0x0000,
  200.   0x0000,
  201.   0x0000,
  202.   0x0000,
  203.   0x0000,
  204.   0x0000,
  205.   0x0000,
  206.   0x0000,
  207.   0x0000,
  208.   0x0000,
  209.   0x0000,
  210.   0x0000,
  211.   0x0000,
  212.   0x0000,
  213.   0x0000,
  214.   0x0000,
  215.   0x0000,
  216.   0x0000,
  217.   0x0000,
  218.   0x0000,
  219.   0x0000,
  220.   0x0000,
  221.   0x0000};
  222. USHORT imagedataz[]=
  223. { 0xfff0,
  224.   0xfff0,
  225.   0xc030,
  226.   0xff70,
  227.   0xfef0,
  228.   0xfdf0,
  229.   0xfbf0,
  230.   0xf7f0,
  231.   0xeff0,
  232.   0xc030,
  233.   0xfff0,
  234.   0xfff0,
  235.   0x0000,
  236.   0x0000,
  237.   0x0000,
  238.   0x0000,
  239.   0x0000,
  240.   0x0000,
  241.   0x0000,
  242.   0x0000,
  243.   0x0000,
  244.   0x0000,
  245.   0x0000,
  246.   0x0000,
  247.   0x0000,
  248.   0x0000,
  249.   0x0000,
  250.   0x0000,
  251.   0x0000,
  252.   0x0000,
  253.   0x0000,
  254.   0x0000,
  255.   0x0000,
  256.   0x0000,
  257.   0x0000,
  258.   0x0000,
  259.   0x0000,
  260.   0x0000,
  261.   0x0000,
  262.   0x0000,
  263.   0x0000,
  264.   0x0000,
  265.   0x0000,
  266.   0x0000,
  267.   0x0000,
  268.   0x0000,
  269.   0x0000,
  270.   0x0000,
  271.   0x0000,
  272.   0x0000,
  273.   0x0000,
  274.   0x0000,
  275.   0x0000,
  276.   0x0000,
  277.   0x0000,
  278.   0x0000,
  279.   0x0000,
  280.   0x0000,
  281.   0x0000,
  282.   0x0000,
  283.   0x0000,
  284.   0x0000,
  285.   0x0000,
  286.   0x0000};
  287.  
  288. struct Image fullimage=
  289. { 0,0,
  290.   16,16,4,
  291.   NULL,
  292.   15,0,
  293.   NULL
  294. };
  295.  
  296. struct Image zoomimage=
  297. { 0,0,
  298.   16,16,4,
  299.   NULL,
  300.   15,0,
  301.   NULL
  302. };
  303.  
  304. struct Border vborder;
  305.  
  306. struct Border hborder;
  307.  
  308.  
  309. struct PropInfo hprop=
  310. { FREEHORIZ|AUTOKNOB,
  311.   0,0,
  312.   0xffff,0xffff,
  313.   0,0,
  314.   0,0,
  315.   0,0
  316. };
  317.  
  318. struct PropInfo vprop=
  319. { FREEVERT|AUTOKNOB,
  320.   0,0,
  321.   0xffff,0xffff,
  322.   0,0,
  323.   0,0,
  324.   0,0
  325. };
  326.  
  327. struct Gadget hgad=
  328. { NULL,
  329.   0,483,
  330.   624,15,
  331.   0,
  332.   GADGIMMEDIATE|RELVERIFY,
  333.   PROPGADGET,
  334.   &hborder,
  335.   NULL,
  336.   NULL,
  337.   0,
  338.   &hprop,
  339.   2,
  340.   NULL
  341. };
  342.  
  343. struct Gadget vgad=
  344. { &hgad,
  345.   625,11,
  346.   15,470,
  347.   0,
  348.   GADGIMMEDIATE|RELVERIFY,
  349.   PROPGADGET,
  350.   &vborder,
  351.   NULL,
  352.   NULL,
  353.   0,
  354.   &vprop,
  355.   1,
  356.   NULL
  357. };
  358.  
  359. struct Gadget zgad=
  360. { &vgad,
  361.   627,485,
  362.   12,12,
  363.   GADGHIMAGE|GADGIMAGE,
  364.   TOGGLESELECT|GADGIMMEDIATE|RELVERIFY,
  365.   BOOLGADGET,
  366.   &fullimage,
  367.   &zoomimage,
  368.   NULL,
  369.   0,
  370.   NULL,
  371.   0,
  372.   NULL
  373. };
  374.  
  375. /* Struktures for Window and Screen */
  376.  
  377. struct NewScreen ns=
  378. {
  379.   0,0,
  380.   640,512,
  381.   4,
  382.   8,1,
  383.   HIRES|LACE,
  384.   CUSTOMSCREEN,
  385.   &textattr,
  386.   (UBYTE *)"Siemens ST 400 Scanner Program © FChK 1991",
  387.   NULL,
  388.   NULL
  389. };
  390.  
  391. struct NewWindow nw=
  392. { 0,10,
  393.   640,500,
  394.   8,1,
  395.   CLOSEWINDOW|MENUPICK|GADGETUP|GADGETDOWN|MOUSEBUTTONS,
  396.   WINDOWCLOSE|BACKDROP|BORDERLESS|ACTIVATE|SMART_REFRESH,
  397.   &zgad,
  398.   NULL,
  399.   (UBYTE *)"",
  400.   NULL,
  401.   NULL,
  402.   0,0,
  403.   0,0,
  404.   CUSTOMSCREEN
  405. };
  406.  
  407. /* AHA-Requester Strukturen */
  408.  
  409. struct IntuiText text_na=
  410. { 0,1,
  411.   JAM2,
  412.   4,7,
  413.   &textattr,
  414.   (UBYTE *)"",
  415.   NULL
  416. };
  417.  
  418. struct IntuiText text_aha=
  419. { 0,1,
  420.   JAM2,
  421.   7,4,
  422.   &textattr,
  423.   (UBYTE *)"OK!",
  424.   NULL
  425. };
  426.  
  427.  
  428. /* Menüdaten und -strukturen */
  429.  
  430. struct IntuiText text5f=
  431. { 0,1,
  432.   JAM2,
  433.   1,1,
  434.   &textattr,
  435.   (UBYTE *)"   15",
  436.   NULL
  437. };
  438.  
  439. struct IntuiText text5e=
  440. { 0,1,
  441.   JAM2,
  442.   1,1,
  443.   &textattr,
  444.   (UBYTE *)"   14",
  445.   NULL
  446. };
  447.  
  448. struct IntuiText text5d=
  449. { 0,1,
  450.   JAM2,
  451.   1,1,
  452.   &textattr,
  453.   (UBYTE *)"   13",
  454.   NULL
  455. };
  456.  
  457. struct IntuiText text5c=
  458. { 0,1,
  459.   JAM2,
  460.   1,1,
  461.   &textattr,
  462.   (UBYTE *)"   12",
  463.   NULL
  464. };
  465.  
  466. struct IntuiText text5b=
  467. { 0,1,
  468.   JAM2,
  469.   1,1,
  470.   &textattr,
  471.   (UBYTE *)"   11",
  472.   NULL
  473. };
  474.  
  475. struct IntuiText text5a=
  476. { 0,1,
  477.   JAM2,
  478.   1,1,
  479.   &textattr,
  480.   (UBYTE *)"   10",
  481.   NULL
  482. };
  483.  
  484. struct IntuiText text59=
  485. { 0,1,
  486.   JAM2,
  487.   1,1,
  488.   &textattr,
  489.   (UBYTE *)"    9",
  490.   NULL
  491. };
  492.  
  493. struct IntuiText text58=
  494. { 0,1,
  495.   JAM2,
  496.   1,1,
  497.   &textattr,
  498.   (UBYTE *)"    8",
  499.   NULL
  500. };
  501.  
  502. struct IntuiText text57=
  503. { 0,1,
  504.   JAM2,
  505.   1,1,
  506.   &textattr,
  507.   (UBYTE *)"    7",
  508.   NULL
  509. };
  510.  
  511. struct IntuiText text56=
  512. { 0,1,
  513.   JAM2,
  514.   1,1,
  515.   &textattr,
  516.   (UBYTE *)"    6",
  517.   NULL
  518. };
  519.  
  520. struct IntuiText text55=
  521. { 0,1,
  522.   JAM2,
  523.   1,1,
  524.   &textattr,
  525.   (UBYTE *)"    5",
  526.   NULL
  527. };
  528.  
  529. struct IntuiText text54=
  530. { 0,1,
  531.   JAM2,
  532.   1,1,
  533.   &textattr,
  534.   (UBYTE *)"    4",
  535.   NULL
  536. };
  537.  
  538. struct IntuiText text53=
  539. { 0,1,
  540.   JAM2,
  541.   1,1,
  542.   &textattr,
  543.   (UBYTE *)"    3",
  544.   NULL
  545. };
  546.  
  547. struct IntuiText text52=
  548. { 0,1,
  549.   JAM2,
  550.   1,1,
  551.   &textattr,
  552.   (UBYTE *)"    2",
  553.   NULL
  554. };
  555.  
  556. struct IntuiText text51=
  557. { 0,1,
  558.   JAM2,
  559.   1,1,
  560.   &textattr,
  561.   (UBYTE *)"    1",
  562.   NULL
  563. };
  564.  
  565. struct IntuiText text50=
  566. { 0,1,
  567.   JAM2,
  568.   1,1,
  569.   &textattr,
  570.   (UBYTE *)"    0",
  571.   NULL
  572. };
  573.  
  574. struct IntuiText text41=
  575. { 0,1,
  576.   JAM2,
  577.   1,1,
  578.   &textattr,
  579.   (UBYTE *)"   16",
  580.   NULL
  581. };
  582.  
  583. struct IntuiText text40=
  584. { 0,1,
  585.   JAM2,
  586.   1,1,
  587.   &textattr,
  588.   (UBYTE *)"    2",
  589.   NULL
  590. };
  591.  
  592. struct IntuiText text31=
  593. { 0,1,
  594.   JAM2,
  595.   1,1,
  596.   &textattr,
  597.   (UBYTE *)"   DIN A4",
  598.   NULL
  599. };
  600.  
  601. struct IntuiText text30=
  602. { 0,1,
  603.   JAM2,
  604.   1,1,
  605.   &textattr,
  606.   (UBYTE *)"   DIN A5",
  607.   NULL
  608. };
  609.  
  610. struct IntuiText text22=
  611. { 0,1,
  612.   JAM2,
  613.   1,1,
  614.   &textattr,
  615.   (UBYTE *)"   400 DPI",
  616.   NULL
  617. };
  618.  
  619. struct IntuiText text21=
  620. { 0,1,
  621.   JAM2,
  622.   1,1,
  623.   &textattr,
  624.   (UBYTE *)"   300 DPI",
  625.   NULL
  626. };
  627.  
  628. struct IntuiText text20=
  629. { 0,1,
  630.   JAM2,
  631.   1,1,
  632.   &textattr,
  633.   (UBYTE *)"   200 DPI",
  634.   NULL
  635. };
  636.  
  637. struct IntuiText text15=
  638. { 0,1,
  639.   JAM2,
  640.   1,1,
  641.   &textattr,
  642.   (UBYTE *)"Exit Program",
  643.   NULL
  644. };
  645.  
  646. struct IntuiText text14=
  647. { 0,1,
  648.   JAM2,
  649.   1,1,
  650.   &textattr,
  651.   (UBYTE *)"Test Scanner",
  652.   NULL
  653. };
  654.  
  655. struct IntuiText text13=
  656. { 0,1,
  657.   JAM2,
  658.   1,1,
  659.   &textattr,
  660.   (UBYTE *)"Dither Ord",
  661.   NULL
  662. };
  663.  
  664. struct IntuiText text12=
  665. { 0,1,
  666.   JAM2,
  667.   1,1,
  668.   &textattr,
  669.   (UBYTE *)"Dither F-S",
  670.   NULL
  671. };
  672.  
  673. struct IntuiText text11=
  674. { 0,1,
  675.   JAM2,
  676.   1,1,
  677.   &textattr,
  678.   (UBYTE *)"Save IFF",
  679.   NULL
  680. };
  681.  
  682. struct IntuiText text10=
  683. { 0,1,
  684.   JAM2,
  685.   1,1,
  686.   &textattr,
  687.   (UBYTE *)"Read Scanner",
  688.   NULL
  689. };
  690.  
  691. struct IntuiText text03=
  692. { 0,1,
  693.   JAM2,
  694.   1,1,
  695.   &textattr,
  696.   (UBYTE *)"Not For Commercial Use",
  697.   NULL
  698. };
  699.  
  700. struct IntuiText text02=
  701. { 0,1,
  702.   JAM2,
  703.   1,1,
  704.   &textattr,
  705.   (UBYTE *)"Version 1.00",
  706.   NULL
  707. };
  708.  
  709.  
  710. struct IntuiText text01=
  711. { 0,1,
  712.   JAM2,
  713.   1,1,
  714.   &textattr,
  715.   (UBYTE *)"Frank-Christian Krügel",
  716.   NULL
  717. };
  718.  
  719. struct IntuiText text00=
  720. { 0,1,
  721.   JAM2,
  722.   1,1,
  723.   &textattr,
  724.   (UBYTE *)"Program written by",
  725.   NULL
  726. };
  727.  
  728. struct MenuItem item5f=
  729. { NULL,
  730.   40,70,
  731.   40,10,
  732.   ITEMTEXT|HIGHCOMP|ITEMENABLED|CHECKIT,
  733.   0x7fff,
  734.   (APTR)&text5f,
  735.   NULL,
  736.   0, 
  737.   NULL,
  738.   0
  739. };
  740.  
  741. struct MenuItem item5e=
  742. { &item5f,
  743.   40,60,
  744.   40,10,
  745.   ITEMTEXT|HIGHCOMP|ITEMENABLED|CHECKIT,
  746.   0xbfff,
  747.   (APTR)&text5e,
  748.   NULL,
  749.   0, 
  750.   NULL,
  751.   0
  752. };
  753.  
  754. struct MenuItem item5d=
  755. { &item5e,
  756.   40,50,
  757.   40,10,
  758.   ITEMTEXT|HIGHCOMP|ITEMENABLED|CHECKIT,
  759.   0xdfff,
  760.   (APTR)&text5d,
  761.   NULL,
  762.   0, 
  763.   NULL,
  764.   0
  765. };
  766.  
  767. struct MenuItem item5c=
  768. { &item5d,
  769.   40,40,
  770.   40,10,
  771.   ITEMTEXT|HIGHCOMP|ITEMENABLED|CHECKIT,
  772.   0xefff,
  773.   (APTR)&text5c,
  774.   NULL,
  775.   0, 
  776.   NULL,
  777.   0
  778. };
  779.  
  780. struct MenuItem item5b=
  781. { &item5c,
  782.   40,30,
  783.   40,10,
  784.   ITEMTEXT|HIGHCOMP|ITEMENABLED|CHECKIT,
  785.   0xf7ff,
  786.   (APTR)&text5b,
  787.   NULL,
  788.   0, 
  789.   NULL,
  790.   0
  791. };
  792.  
  793. struct MenuItem item5a=
  794. { &item5b,
  795.   40,20,
  796.   40,10,
  797.   ITEMTEXT|HIGHCOMP|ITEMENABLED|CHECKIT,
  798.   0xfbff,
  799.   (APTR)&text5a,
  800.   NULL,
  801.   0, 
  802.   NULL,
  803.   0
  804. };
  805.  
  806. struct MenuItem item59=
  807. { &item5a,
  808.   40,10,
  809.   40,10,
  810.   ITEMTEXT|HIGHCOMP|ITEMENABLED|CHECKIT,
  811.   0xfdff,
  812.   (APTR)&text59,
  813.   NULL,
  814.   0, 
  815.   NULL,
  816.   0
  817. };
  818.  
  819. struct MenuItem item58=
  820. { &item59,
  821.   40,0,
  822.   40,10,
  823.   ITEMTEXT|HIGHCOMP|ITEMENABLED|CHECKIT|CHECKED,
  824.   0xfeff,
  825.   (APTR)&text58,
  826.   NULL,
  827.   0, 
  828.   NULL,
  829.   0
  830. };
  831.  
  832. struct MenuItem item57=
  833. { &item58,
  834.   0,70,
  835.   40,10,
  836.   ITEMTEXT|HIGHCOMP|ITEMENABLED|CHECKIT,
  837.   0xff7f,
  838.   (APTR)&text57,
  839.   NULL,
  840.   0, 
  841.   NULL,
  842.   0
  843. };
  844.  
  845. struct MenuItem item56=
  846. { &item57,
  847.   0,60,
  848.   40,10,
  849.   ITEMTEXT|HIGHCOMP|ITEMENABLED|CHECKIT,
  850.   0xffbf,
  851.   (APTR)&text56,
  852.   NULL,
  853.   0, 
  854.   NULL,
  855.   0
  856. };
  857.  
  858. struct MenuItem item55=
  859. { &item56,
  860.   0,50,
  861.   40,10,
  862.   ITEMTEXT|HIGHCOMP|ITEMENABLED|CHECKIT,
  863.   0xffdf,
  864.   (APTR)&text55,
  865.   NULL,
  866.   0, 
  867.   NULL,
  868.   0
  869. };
  870.  
  871. struct MenuItem item54=
  872. { &item55,
  873.   0,40,
  874.   40,10,
  875.   ITEMTEXT|HIGHCOMP|ITEMENABLED|CHECKIT,
  876.   0xffef,
  877.   (APTR)&text54,
  878.   NULL,
  879.   0, 
  880.   NULL,
  881.   0
  882. };
  883.  
  884. struct MenuItem item53=
  885. { &item54,
  886.   0,30,
  887.   40,10,
  888.   ITEMTEXT|HIGHCOMP|ITEMENABLED|CHECKIT,
  889.   0xfff7,
  890.   (APTR)&text53,
  891.   NULL,
  892.   0, 
  893.   NULL,
  894.   0
  895. };
  896.  
  897. struct MenuItem item52=
  898. { &item53,
  899.   0,20,
  900.   40,10,
  901.   ITEMTEXT|HIGHCOMP|ITEMENABLED|CHECKIT,
  902.   0xfffb,
  903.   (APTR)&text52,
  904.   NULL,
  905.   0, 
  906.   NULL,
  907.   0
  908. };
  909.  
  910. struct MenuItem item51=
  911. { &item52,
  912.   0,10,
  913.   40,10,
  914.   ITEMTEXT|HIGHCOMP|ITEMENABLED|CHECKIT,
  915.   0xfffd,
  916.   (APTR)&text51,
  917.   NULL,
  918.   0, 
  919.   NULL,
  920.   0
  921. };
  922.  
  923. struct MenuItem item50=
  924. { &item51,
  925.   0,0,
  926.   40,10,
  927.   ITEMTEXT|HIGHCOMP|ITEMENABLED|CHECKIT,
  928.   0xfffe,
  929.   (APTR)&text50,
  930.   NULL,
  931.   0, 
  932.   NULL,
  933.   0
  934. };
  935.  
  936.  
  937. struct MenuItem item41=
  938. { NULL,
  939.   0,10,
  940.   80,10,
  941.   ITEMTEXT|HIGHCOMP|ITEMENABLED|CHECKIT|COMMSEQ,
  942.   0xfffd,
  943.   (APTR)&text41,
  944.   NULL,
  945.   'g', 
  946.   NULL,
  947.   0
  948. };
  949.  
  950. struct MenuItem item40=
  951. { &item41,
  952.   0,0,
  953.   80,10,
  954.   ITEMTEXT|HIGHCOMP|ITEMENABLED|CHECKIT|CHECKED|COMMSEQ,
  955.   0xfffe,
  956.   (APTR)&text40,
  957.   NULL,
  958.   'z', 
  959.   NULL,
  960.   0
  961. };
  962.  
  963.  
  964. struct MenuItem item31=
  965. { NULL,
  966.   0,10,
  967.   112,10,
  968.   ITEMTEXT|HIGHCOMP|ITEMENABLED|CHECKIT|COMMSEQ,
  969.   0xfffd,
  970.   (APTR)&text31,
  971.   NULL,
  972.   'b', 
  973.   NULL,
  974.   0
  975. };
  976.  
  977. struct MenuItem item30=
  978. { &item31,
  979.   0,0,
  980.   112,10,
  981.   ITEMTEXT|HIGHCOMP|ITEMENABLED|CHECKIT|CHECKED|COMMSEQ,
  982.   0xfffe,
  983.   (APTR)&text30,
  984.   NULL,
  985.   'a', 
  986.   NULL,
  987.   0
  988. };
  989.  
  990.  
  991. struct MenuItem item22=
  992. { NULL,
  993.   0,20,
  994.   120,10,
  995.   ITEMTEXT|HIGHCOMP|ITEMENABLED|CHECKIT|COMMSEQ,
  996.   0xfffb,
  997.   (APTR)&text22,
  998.   NULL,
  999.   '3', 
  1000.   NULL,
  1001.   0
  1002. };
  1003.  
  1004. struct MenuItem item21=
  1005. { &item22,
  1006.   0,10,
  1007.   120,10,
  1008.   ITEMTEXT|HIGHCOMP|ITEMENABLED|CHECKIT|COMMSEQ,
  1009.   0xfffd,
  1010.   (APTR)&text21,
  1011.   NULL,
  1012.   '3', 
  1013.   NULL,
  1014.   0
  1015. };
  1016.  
  1017.  
  1018. struct MenuItem item20=
  1019. { &item21,
  1020.   0,0,
  1021.   120,10,
  1022.   ITEMTEXT|HIGHCOMP|ITEMENABLED|CHECKIT|CHECKED|COMMSEQ,
  1023.   0xfffe,
  1024.   (APTR)&text20,
  1025.   NULL,
  1026.   '2', 
  1027.   NULL,
  1028.   0
  1029. };
  1030.  
  1031.  
  1032. struct MenuItem item15=
  1033. { NULL,
  1034.   0,50,
  1035.   176,10,
  1036.   ITEMTEXT|HIGHCOMP|ITEMENABLED|COMMSEQ,
  1037.   0,
  1038.   (APTR)&text15,
  1039.   NULL,
  1040.   'x',
  1041.   NULL,
  1042.   0
  1043. };
  1044.  
  1045. struct MenuItem item14=
  1046. { &item15,
  1047.   0,40,
  1048.   176,10,
  1049.   ITEMTEXT|HIGHCOMP|ITEMENABLED|COMMSEQ,
  1050.   0,
  1051.   (APTR)&text14,
  1052.   NULL,
  1053.   't',
  1054.   NULL,
  1055.   0
  1056. };
  1057.  
  1058. struct MenuItem item13=
  1059. { &item14,
  1060.   0,30,
  1061.   176,10,
  1062.   ITEMTEXT|HIGHCOMP|ITEMENABLED,
  1063.   0,
  1064.   (APTR)&text13,
  1065.   NULL,
  1066.   0,
  1067.   NULL,
  1068.   0
  1069. };
  1070.  
  1071. struct MenuItem item12=
  1072. { &item13,
  1073.   0,20,
  1074.   176,10,
  1075.   ITEMTEXT|HIGHCOMP|ITEMENABLED,
  1076.   0,
  1077.   (APTR)&text12,
  1078.   NULL,
  1079.   0,
  1080.   NULL,
  1081.   0
  1082. };
  1083.  
  1084. struct MenuItem item11=
  1085. { &item12,
  1086.   0,10,
  1087.   176,10,
  1088.   ITEMTEXT|HIGHCOMP|ITEMENABLED|COMMSEQ,
  1089.   0,
  1090.   (APTR)&text11,
  1091.   NULL,
  1092.   's',
  1093.   NULL,
  1094.   0
  1095. };
  1096.     
  1097. struct MenuItem item10=
  1098. { &item11,
  1099.   0,0,
  1100.   176,10,
  1101.   ITEMTEXT|HIGHCOMP|ITEMENABLED|COMMSEQ,
  1102.   0,
  1103.   (APTR)&text10,
  1104.   NULL,
  1105.   'r',
  1106.   NULL,
  1107.   0
  1108. };
  1109.  
  1110. struct MenuItem item03=
  1111. { NULL,
  1112.   0,30,
  1113.   160,10,
  1114.   ITEMTEXT|HIGHNONE|ITEMENABLED,
  1115.   0,
  1116.   (APTR)&text03,
  1117.   NULL,
  1118.   0,
  1119.   NULL,
  1120.   0
  1121. };
  1122.  
  1123. struct MenuItem item02=
  1124. { &item03,
  1125.   0,20,
  1126.   160,10,
  1127.   ITEMTEXT|HIGHNONE|ITEMENABLED,
  1128.   0,
  1129.   (APTR)&text02,
  1130.   NULL,
  1131.   0,
  1132.   NULL,
  1133.   0
  1134. };
  1135.  
  1136. struct MenuItem item01=
  1137. { &item02,
  1138.   0,10,
  1139.   160,10,
  1140.   ITEMTEXT|HIGHNONE|ITEMENABLED,
  1141.   0,
  1142.   (APTR)&text01,
  1143.   NULL,
  1144.   0,
  1145.   NULL,
  1146.   0
  1147. };
  1148.  
  1149. struct MenuItem item00=
  1150. { &item01,
  1151.   0,0,
  1152.   160,10,
  1153.   ITEMTEXT|HIGHNONE|ITEMENABLED,
  1154.   0,
  1155.   (APTR)&text00,
  1156.   NULL,
  1157.   0,
  1158.   NULL,
  1159.   0
  1160. };
  1161.  
  1162.  
  1163. struct Menu menu5=
  1164. { NULL,
  1165.   448,0,
  1166.   80,0,
  1167.   MENUENABLED,
  1168.   "Threshold",
  1169.   &item50
  1170. };
  1171.  
  1172. struct Menu menu4=
  1173. { &menu5,
  1174.   336,0,
  1175.   88,8,
  1176.   MENUENABLED,
  1177.   "Gray Scale",
  1178.   &item40
  1179. };
  1180.  
  1181. struct Menu menu3=
  1182. { &menu4,
  1183.   256,0,
  1184.   40,8,
  1185.   MENUENABLED,
  1186.   "Size",
  1187.   &item30
  1188. };
  1189.  
  1190. struct Menu menu2=
  1191. { &menu3,
  1192.   160,0,
  1193.   88,8,
  1194.   MENUENABLED,
  1195.   "Resolution",
  1196.   &item20
  1197. };
  1198.  
  1199. struct Menu menu1=
  1200. { &menu2,
  1201.   64,0,
  1202.   72,8,
  1203.   MENUENABLED,
  1204.   "Program",
  1205.   &item10
  1206. };
  1207.  
  1208. struct Menu menu0=
  1209. { &menu1,
  1210.   0,0,
  1211.   40,8,
  1212.   MENUENABLED,
  1213.   "Info",
  1214.   &item00
  1215. };
  1216.  
  1217. /* Program Code */
  1218.  
  1219. /* Call of the Heath File Requester */
  1220.  
  1221. USHORT filerequest(char *titel)
  1222. {
  1223. struct Process    *OurTask;
  1224. struct Window    *old_pr_WindowPtr;
  1225.  
  1226.     OurTask = (struct Process *)FindTask((char *)0L);
  1227.     old_pr_WindowPtr = OurTask->pr_WindowPtr;
  1228.     OurTask->pr_WindowPtr = win;
  1229.  
  1230.     if (get_fname(win,win->WScreen,"Choose File",def_name,def_dir)==NULL)
  1231.     { OurTask->pr_WindowPtr = old_pr_WindowPtr;
  1232.       return(0);
  1233.     }
  1234.     else
  1235.     {
  1236.       OurTask->pr_WindowPtr = old_pr_WindowPtr;
  1237.       strcpy(str_filenam,def_dir);
  1238.       rfnam(str_filenam,def_name);
  1239.       return(1);
  1240.     }
  1241.  
  1242.  
  1243. void MessReq(UBYTE *string)
  1244. {  ULONG dummy;
  1245.    text_na.IText=string;
  1246.    dummy=(ULONG)AutoRequest(win,&text_na,NULL,&text_aha,NULL,NULL,400L,60L);
  1247. }
  1248.  
  1249. void NotAvailable()
  1250. {  MessReq((UBYTE *)"Funktion not available!");
  1251. }
  1252.  
  1253. UBYTE DoScsi(UBYTE *cmd, UWORD cmdlen, UWORD *data, ULONG datalen, UBYTE flags)
  1254. { struct SCSICmd scmd;
  1255.   scmd.scsi_Command=cmd;
  1256.   scmd.scsi_CmdLength=cmdlen;
  1257.   scmd.scsi_Data=data;
  1258.   scmd.scsi_Length=datalen;
  1259.   scmd.scsi_Flags=flags;
  1260.   diskreq->io_Length = sizeof(struct SCSICmd);
  1261.   diskreq->io_Data = &scmd;
  1262.   diskreq->io_Command = 28;
  1263.   DoIO(diskreq);
  1264.   return(scmd.scsi_Status);
  1265. }
  1266.  
  1267.  
  1268. void inquiry()
  1269. { UBYTE string[96],inq_txt[45];
  1270.  
  1271.   DoScsi(&cmd_inqu,6,(UWORD *)&string,96,DIR_READ);
  1272.   strncpy(&inq_txt[0],&string[8],41);
  1273.   MessReq(&inq_txt[0]);
  1274. }
  1275.  
  1276. void p64to16(UBYTE *ptr, UWORD size)
  1277. { UBYTE *p1,*p2;
  1278.   UWORD i;
  1279.  
  1280.   cnt=size;
  1281.   p0=ptr;
  1282. #asm
  1283.     movem.l    d0-d7/a0-a6,-(a7)
  1284.     move.w    _cnt,d7
  1285.     subq.w    #1,d7
  1286.     move.l    _p0,a0
  1287.     move.l    _p0,a1
  1288. slp:    move.w    (a0)+,d0
  1289.     lsr.w    #2,d0
  1290.     lsl.b    #4,d0
  1291.     lsr.w    #4,d0
  1292.     move.b    d0,(a1)+
  1293.     dbra    d7,slp
  1294.     movem.l (a7)+,d0-d7/a0-a6
  1295. #endasm
  1296. }
  1297.  
  1298. void clrscr(UBYTE *pl0, UBYTE *pl1, UBYTE *pl2, UBYTE *pl3)
  1299. { p1=pl0; p2=pl1; p3=pl2; p4=pl3;
  1300. #asm
  1301.     movem.l    d5-d7/a0-a6,-(a7)
  1302.     move.l    _p1,a1
  1303.     move.l    _p2,a2
  1304.     move.l    _p3,a3
  1305.     move.l    _p4,a4
  1306.     move.w    #469,d5
  1307. clrlp0:    move.w    #38,d7
  1308. clrlp1:    clr.w    (a1)+
  1309.     clr.w    (a2)+
  1310.     clr.w    (a3)+
  1311.     clr.w    (a4)+
  1312.     dbra    d7,clrlp1
  1313.     lea.l    2(a1),a1
  1314.     lea.l    2(a2),a2
  1315.     lea.l    2(a3),a3
  1316.     lea.l    2(a4),a4
  1317.     dbra    d5,clrlp0
  1318.     movem.l    (a7)+,d5-d7/a0-a6
  1319. #endasm
  1320. }
  1321.  
  1322. void bwview(UBYTE *vp, UBYTE *pl0, UBYTE *pl1, UBYTE *pl2, UBYTE *pl3, ULONG vinc) 
  1323. { p0=vp; p1=pl0; p2=pl1; p3=pl2; p4=pl3; v1=vinc;
  1324. #asm
  1325.     movem.l    d5-d7/a0-a6,-(a7)
  1326.     move.l    _p0,a0
  1327.     move.l    _p1,a1
  1328.     move.l    _p2,a2
  1329.     move.l    _p3,a3
  1330.     move.l    _p4,a4
  1331.     move.l    _v1,a5
  1332.     move.w    #469,d5
  1333. bwlp0:    move.l    a0,a6
  1334.     move.w    #38,d7
  1335. bwlp1:    move.w    (a6)+,d6
  1336.     move.w    d6,(a1)+
  1337.     clr.w    (a2)+
  1338.     clr.w    (a3)+
  1339.     clr.w    (a4)+
  1340.     dbra    d7,bwlp1
  1341.     lea.l    2(a1),a1
  1342.     lea.l    2(a2),a2
  1343.     lea.l    2(a3),a3
  1344.     lea.l    2(a4),a4
  1345.     adda.l    a5,a0
  1346.     dbra    d5,bwlp0
  1347.     movem.l    (a7)+,d5-d7/a0-a6
  1348. #endasm
  1349. }
  1350.  
  1351. void grayview(UBYTE *vp, UBYTE *pl0, UBYTE *pl1, UBYTE *pl2, UBYTE *pl3, ULONG vinc) 
  1352. { p0=vp; p1=pl0; p2=pl1; p3=pl2; p4=pl3; v1=vinc;
  1353. #asm
  1354.     movem.l    d0-d7/a0-a6,-(a7)
  1355.     move.l    _p0,a0
  1356.     move.l    _p1,a1
  1357.     move.l    _p2,a2
  1358.     move.l    _p3,a3
  1359.     move.l    _p4,a4
  1360.     move.l    _v1,a5
  1361.     move.l  #$10000000,d6
  1362.     move.w    #469,d5
  1363. grlp0:    move.l    a0,a6
  1364.     move.w    #77,d7
  1365. grlp1:    move.l    (a6)+,d0
  1366.     add.l    d6,d0
  1367.     lsl.l    #1,d0
  1368.     roxl.b    #1,d4
  1369.     lsl.l    #1,d0
  1370.     roxl.b    #1,d3
  1371.     lsl.l    #1,d0
  1372.     roxl.b    #1,d2
  1373.     lsl.l    #1,d0
  1374.     roxl.b    #1,d1
  1375.     add.l    d6,d0
  1376.     lsl.l    #1,d0
  1377.     roxl.b    #1,d4
  1378.     lsl.l    #1,d0
  1379.     roxl.b    #1,d3
  1380.     lsl.l    #1,d0
  1381.     roxl.b    #1,d2
  1382.     lsl.l    #1,d0
  1383.     roxl.b    #1,d1
  1384.     add.l    d6,d0
  1385.     lsl.l    #1,d0
  1386.     roxl.b    #1,d4
  1387.     lsl.l    #1,d0
  1388.     roxl.b    #1,d3
  1389.     lsl.l    #1,d0
  1390.     roxl.b    #1,d2
  1391.     lsl.l    #1,d0
  1392.     roxl.b    #1,d1
  1393.     add.l    d6,d0
  1394.     lsl.l    #1,d0
  1395.     roxl.b    #1,d4
  1396.     lsl.l    #1,d0
  1397.     roxl.b    #1,d3
  1398.     lsl.l    #1,d0
  1399.     roxl.b    #1,d2
  1400.     lsl.l    #1,d0
  1401.     roxl.b    #1,d1
  1402.     add.l    d6,d0
  1403.     lsl.l    #1,d0
  1404.     roxl.b    #1,d4
  1405.     lsl.l    #1,d0
  1406.     roxl.b    #1,d3
  1407.     lsl.l    #1,d0
  1408.     roxl.b    #1,d2
  1409.     lsl.l    #1,d0
  1410.     roxl.b    #1,d1
  1411.     add.l    d6,d0
  1412.     lsl.l    #1,d0
  1413.     roxl.b    #1,d4
  1414.     lsl.l    #1,d0
  1415.     roxl.b    #1,d3
  1416.     lsl.l    #1,d0
  1417.     roxl.b    #1,d2
  1418.     lsl.l    #1,d0
  1419.     roxl.b    #1,d1
  1420.     add.l    d6,d0
  1421.     lsl.l    #1,d0
  1422.     roxl.b    #1,d4
  1423.     lsl.l    #1,d0
  1424.     roxl.b    #1,d3
  1425.     lsl.l    #1,d0
  1426.     roxl.b    #1,d2
  1427.     lsl.l    #1,d0
  1428.     roxl.b    #1,d1
  1429.     add.l    d6,d0
  1430.     lsl.l    #1,d0
  1431.     roxl.b    #1,d4
  1432.     lsl.l    #1,d0
  1433.     roxl.b    #1,d3
  1434.     lsl.l    #1,d0
  1435.     roxl.b    #1,d2
  1436.     lsl.l    #1,d0
  1437.     roxl.b    #1,d1
  1438.     move.b    d1,(a1)+
  1439.     move.b    d2,(a2)+
  1440.     move.b    d3,(a3)+
  1441.     move.b    d4,(a4)+
  1442.     dbra    d7,grlp1
  1443.     lea.l    2(a1),a1
  1444.     lea.l    2(a2),a2
  1445.     lea.l    2(a3),a3
  1446.     lea.l    2(a4),a4
  1447.     adda.l    a5,a0
  1448.     dbra    d5,grlp0
  1449.     movem.l    (a7)+,d0-d7/a0-a6
  1450. #endasm
  1451. }
  1452.  
  1453. void vplanesep(UBYTE *vp, UBYTE *pl0, UBYTE *pl1, UBYTE *pl2, UBYTE *pl3, UWORD count) 
  1454. { p0=vp; p1=pl0; p2=pl1; p3=pl2; p4=pl3; cnt=count;
  1455. #asm
  1456.     movem.l    d0-d7/a0-a6,-(a7)
  1457.     move.w    _cnt,d7
  1458.     move.l    _p0,a0
  1459.     move.l    _p1,a1
  1460.     move.l    _p2,a2
  1461.     move.l    _p3,a3
  1462.     move.l    _p4,a4
  1463.     move.l  #$10000000,d6
  1464.      subq.w    #1,d7
  1465. vplp:    move.l    (a0)+,d0
  1466.     add.l    d6,d0
  1467.     lsl.l    #1,d0
  1468.     roxl.b    #1,d4
  1469.     lsl.l    #1,d0
  1470.     roxl.b    #1,d3
  1471.     lsl.l    #1,d0
  1472.     roxl.b    #1,d2
  1473.     lsl.l    #1,d0
  1474.     roxl.b    #1,d1
  1475.     add.l    d6,d0
  1476.     lsl.l    #1,d0
  1477.     roxl.b    #1,d4
  1478.     lsl.l    #1,d0
  1479.     roxl.b    #1,d3
  1480.     lsl.l    #1,d0
  1481.     roxl.b    #1,d2
  1482.     lsl.l    #1,d0
  1483.     roxl.b    #1,d1
  1484.     add.l    d6,d0
  1485.     lsl.l    #1,d0
  1486.     roxl.b    #1,d4
  1487.     lsl.l    #1,d0
  1488.     roxl.b    #1,d3
  1489.     lsl.l    #1,d0
  1490.     roxl.b    #1,d2
  1491.     lsl.l    #1,d0
  1492.     roxl.b    #1,d1
  1493.     add.l    d6,d0
  1494.     lsl.l    #1,d0
  1495.     roxl.b    #1,d4
  1496.     lsl.l    #1,d0
  1497.     roxl.b    #1,d3
  1498.     lsl.l    #1,d0
  1499.     roxl.b    #1,d2
  1500.     lsl.l    #1,d0
  1501.     roxl.b    #1,d1
  1502.     add.l    d6,d0
  1503.     lsl.l    #1,d0
  1504.     roxl.b    #1,d4
  1505.     lsl.l    #1,d0
  1506.     roxl.b    #1,d3
  1507.     lsl.l    #1,d0
  1508.     roxl.b    #1,d2
  1509.     lsl.l    #1,d0
  1510.     roxl.b    #1,d1
  1511.     add.l    d6,d0
  1512.     lsl.l    #1,d0
  1513.     roxl.b    #1,d4
  1514.     lsl.l    #1,d0
  1515.     roxl.b    #1,d3
  1516.     lsl.l    #1,d0
  1517.     roxl.b    #1,d2
  1518.     lsl.l    #1,d0
  1519.     roxl.b    #1,d1
  1520.     add.l    d6,d0
  1521.     lsl.l    #1,d0
  1522.     roxl.b    #1,d4
  1523.     lsl.l    #1,d0
  1524.     roxl.b    #1,d3
  1525.     lsl.l    #1,d0
  1526.     roxl.b    #1,d2
  1527.     lsl.l    #1,d0
  1528.     roxl.b    #1,d1
  1529.     add.l    d6,d0
  1530.     lsl.l    #1,d0
  1531.     roxl.b    #1,d4
  1532.     lsl.l    #1,d0
  1533.     roxl.b    #1,d3
  1534.     lsl.l    #1,d0
  1535.     roxl.b    #1,d2
  1536.     lsl.l    #1,d0
  1537.     roxl.b    #1,d1
  1538.     move.b    d1,(a1)+
  1539.     move.b    d2,(a2)+
  1540.     move.b    d3,(a3)+
  1541.     move.b    d4,(a4)+
  1542.     dbra    d7,vplp
  1543.     movem.l    (a7)+,d0-d7/a0-a6
  1544. #endasm
  1545. }
  1546.  
  1547. void fplanesep(UBYTE *vp, UBYTE *pl0, UBYTE *pl1, UBYTE *pl2, UBYTE *pl3, UWORD count) 
  1548. { p0=vp; p1=pl0; p2=pl1; p3=pl2; p4=pl3; cnt=count;
  1549. #asm
  1550.     movem.l    d0-d7/a0-a6,-(a7)
  1551.     move.w    _cnt,d7
  1552.     move.l    _p0,a0
  1553.     move.l    _p1,a1
  1554.     move.l    _p2,a2
  1555.     move.l    _p3,a3
  1556.     move.l    _p4,a4
  1557.      subq.w    #1,d7
  1558. fplp:    move.l    (a0)+,d0
  1559.     lsl.l    #1,d0
  1560.     roxl.b    #1,d4
  1561.     lsl.l    #1,d0
  1562.     roxl.b    #1,d3
  1563.     lsl.l    #1,d0
  1564.     roxl.b    #1,d2
  1565.     lsl.l    #1,d0
  1566.     roxl.b    #1,d1
  1567.     lsl.l    #1,d0
  1568.     roxl.b    #1,d4
  1569.     lsl.l    #1,d0
  1570.     roxl.b    #1,d3
  1571.     lsl.l    #1,d0
  1572.     roxl.b    #1,d2
  1573.     lsl.l    #1,d0
  1574.     roxl.b    #1,d1
  1575.     lsl.l    #1,d0
  1576.     roxl.b    #1,d4
  1577.     lsl.l    #1,d0
  1578.     roxl.b    #1,d3
  1579.     lsl.l    #1,d0
  1580.     roxl.b    #1,d2
  1581.     lsl.l    #1,d0
  1582.     roxl.b    #1,d1
  1583.     lsl.l    #1,d0
  1584.     roxl.b    #1,d4
  1585.     lsl.l    #1,d0
  1586.     roxl.b    #1,d3
  1587.     lsl.l    #1,d0
  1588.     roxl.b    #1,d2
  1589.     lsl.l    #1,d0
  1590.     roxl.b    #1,d1
  1591.     lsl.l    #1,d0
  1592.     roxl.b    #1,d4
  1593.     lsl.l    #1,d0
  1594.     roxl.b    #1,d3
  1595.     lsl.l    #1,d0
  1596.     roxl.b    #1,d2
  1597.     lsl.l    #1,d0
  1598.     roxl.b    #1,d1
  1599.     lsl.l    #1,d0
  1600.     roxl.b    #1,d4
  1601.     lsl.l    #1,d0
  1602.     roxl.b    #1,d3
  1603.     lsl.l    #1,d0
  1604.     roxl.b    #1,d2
  1605.     lsl.l    #1,d0
  1606.     roxl.b    #1,d1
  1607.     lsl.l    #1,d0
  1608.     roxl.b    #1,d4
  1609.     lsl.l    #1,d0
  1610.     roxl.b    #1,d3
  1611.     lsl.l    #1,d0
  1612.     roxl.b    #1,d2
  1613.     lsl.l    #1,d0
  1614.     roxl.b    #1,d1
  1615.     lsl.l    #1,d0
  1616.     roxl.b    #1,d4
  1617.     lsl.l    #1,d0
  1618.     roxl.b    #1,d3
  1619.     lsl.l    #1,d0
  1620.     roxl.b    #1,d2
  1621.     lsl.l    #1,d0
  1622.     roxl.b    #1,d1
  1623.     not.b    d1
  1624.     not.b    d2
  1625.     not.b    d3
  1626.     not.b    d4
  1627.     move.b    d1,(a1)+
  1628.     move.b    d2,(a2)+
  1629.     move.b    d3,(a3)+
  1630.     move.b    d4,(a4)+
  1631.     dbra    d7,fplp
  1632.     movem.l    (a7)+,d0-d7/a0-a6
  1633. #endasm
  1634. }
  1635.  
  1636. void scan()
  1637. { ULONG memsize,blsize;
  1638.   short tabindex,blocks,rest,i,glin,rlin;
  1639.   UBYTE *rdptr;
  1640.  
  1641.   if (memptr) free(memptr);
  1642.   memneed=0;
  1643.   tabindex=((winpar.resx/100)-2)+(winpar.size-4)*3;
  1644.   winpar.cornerx=cornerxval[tabindex];
  1645.   winpar.cornery=corneryval[tabindex];
  1646.   winpar.width=widthval[tabindex];
  1647.   winpar.height=heightval[tabindex];
  1648.   memsize=(winpar.halftone)?((ULONG)winpar.width*(ULONG)winpar.height)>>1:
  1649.                             ((ULONG)winpar.width*(ULONG)winpar.height)>>3;
  1650.   if ((memptr=(UBYTE*)malloc(memsize))==NULL) 
  1651.     MessReq((UBYTE*)"Nicht genug Speicher für diese Einstellung!");
  1652.   else 
  1653.   { memneed=memsize;
  1654.     memwidth=winpar.width;
  1655.     memheight=winpar.height;
  1656.     memgray=winpar.halftone;
  1657.     rdptr=memptr;
  1658.     if (!(winpar.halftone))
  1659.     { DoScsi(&cmd_mdon,6,NULL,0,0);
  1660.       Delay(100);
  1661.       DoScsi(&cmd_dwin,10,&winpar,40,DIR_WRITE);
  1662.       DoScsi(&cmd_scan,6,NULL,0,0);
  1663.       blocks=memsize/0x8000;
  1664.       rest=memsize%0x8000;
  1665.       cmd_read[7]=128; cmd_read[8]=0;
  1666.       for (i=0;i<blocks;i++) 
  1667.       { DoScsi(&cmd_read,10,rdptr,0x8000,DIR_READ);
  1668.         rdptr+=0x8000;
  1669.       }
  1670.       cmd_read[7]=(rest>>8)&0xff; cmd_read[8]=rest&0xff;
  1671.       DoScsi(&cmd_read,10,rdptr,rest,DIR_READ);
  1672.       rdptr+=rest;
  1673.     }
  1674.     else
  1675.     { glin=winpar.height;
  1676.       rlin=0x200000L/(ULONG)winpar.width; 
  1677.       do 
  1678.       { if (rlin>glin) rlin=glin;
  1679.         winpar.height=rlin;
  1680.         glin-=rlin;
  1681.         DoScsi(&cmd_mdon,6,NULL,0,0);
  1682.         Delay(100);
  1683.         DoScsi(&cmd_dwin,10,&winpar,40,DIR_WRITE);
  1684.         DoScsi(&cmd_scan,6,NULL,0,0);
  1685.     winpar.cornery+=rlin;
  1686.         blsize=((ULONG)winpar.height*(ULONG)winpar.width)>>1;
  1687.         blocks=blsize/0x4000;
  1688.         rest=blsize%0x4000;
  1689.         cmd_read[7]=128; cmd_read[8]=0;
  1690.         for (i=0;i<blocks;i++) 
  1691.         { DoScsi(&cmd_read,10,rdptr,0x8000,DIR_READ);
  1692.           p64to16(rdptr,0x4000);
  1693.           rdptr+=0x4000;
  1694.         }
  1695.         cmd_read[7]=(rest>>7)&0xff; cmd_read[8]=(rest<<1)&0xff;
  1696.         DoScsi(&cmd_read,10,rdptr,rest<<1,DIR_READ);
  1697.         p64to16(rdptr,rest);
  1698.     rdptr+=rest;
  1699.       } while (glin);
  1700.     }
  1701.     DoScsi(&cmd_mdoff,6,NULL,0,0); 
  1702.   }
  1703. }  
  1704.     
  1705. void view(UWORD x, UWORD y, UBYTE zoom)
  1706. { UBYTE *vptr;
  1707.   UBYTE *plptr[4];
  1708.   ULONG vinc;
  1709.   ULONG vicr[13];
  1710.   UWORD i,j,k,n1,n2,zeile;
  1711.   UBYTE linebuf[1000];
  1712.  
  1713.   for (i=0;i<4;i++) plptr[i]=(UBYTE *)(rp->BitMap->Planes[i]+1680);
  1714.   vptr=(memgray)?
  1715.        (UBYTE*)(memptr+(((memwidth>>1)*y)+(x>>1))):
  1716.        (UBYTE*)(memptr+(((memwidth>>3)*y)+(x>>3)));
  1717.   vinc=(memgray)?(ULONG)(memwidth>>1):(ULONG)(memwidth>>3);
  1718.   if (zoom)
  1719.   { if ((memheight/4)<470) sk=4;
  1720.     else if ((memheight/8)<470) sk=8;
  1721.     else if ((memheight/12)<470) sk=12;
  1722.     vptr=memptr;
  1723.     vicr[0]=0; vicr[1]=vinc;
  1724.     for (i=2;i<13;i++) vicr[i]=vicr[i-1]+vinc;
  1725.     clrscr(plptr[0],plptr[1],plptr[2],plptr[3]);
  1726.     zeile=0; vx=vy=0;
  1727.     if (memgray)
  1728.     switch (sk)
  1729.     { case 4: while(zeile<memheight)
  1730.               { zeile+=4;
  1731.                 for (i=0;i<(memwidth>>1);i+=4)
  1732.                 { n1=n2=0; j=i;
  1733.                   for (k=0;k<4;k++)
  1734.                   { n1+=((*(vptr+j  )>>4)+(*(vptr+j  )&15)+(*(vptr+j+1)>>4)+(*(vptr+j+1)&15));
  1735.                     n2+=((*(vptr+j+2)>>4)+(*(vptr+j+2)&15)+(*(vptr+j+3)>>4)+(*(vptr+j+3)&15));
  1736.                     j+=vinc;
  1737.                   }
  1738.                   linebuf[i>>2]=(n1&0xf0)|(n2>>4);
  1739.                 }
  1740.                 vplanesep(&linebuf[0],plptr[0],plptr[1],plptr[2],plptr[3],memwidth>>5);
  1741.                 plptr[0]+=80; plptr[1]+=80; plptr[2]+=80; plptr[3]+=80;
  1742.                 vptr+=vicr[4];
  1743.               } 
  1744.               break;
  1745.       case 8: while(zeile<memheight)
  1746.               { zeile+=8;
  1747.                 for (i=0;i<(memwidth>>1);i+=8)
  1748.                 { n1=n2=0; j=i;
  1749.                   for (k=0;k<8;k++)
  1750.                   { n1+=((*(vptr+j  )>>4)+(*(vptr+j  )&15)+(*(vptr+j+1)>>4)+(*(vptr+j+1)&15)
  1751.                         +(*(vptr+j+2)>>4)+(*(vptr+j+2)&15)+(*(vptr+j+3)>>4)+(*(vptr+j+3)&15));
  1752.                     n2+=((*(vptr+j+4)>>4)+(*(vptr+j+4)&15)+(*(vptr+j+5)>>4)+(*(vptr+j+5)&15)
  1753.                         +(*(vptr+j+6)>>4)+(*(vptr+j+6)&15)+(*(vptr+j+7)>>4)+(*(vptr+j+7)&15));
  1754.                     j+=vinc;
  1755.                   }
  1756.                   linebuf[i>>3]=((n1>>2)&0xf0)|((n2>>6)&0x0f);
  1757.                 }
  1758.                 vplanesep(&linebuf[0],plptr[0],plptr[1],plptr[2],plptr[3],memwidth>>6);
  1759.                 plptr[0]+=80; plptr[1]+=80; plptr[2]+=80; plptr[3]+=80;
  1760.                 vptr+=vicr[8];
  1761.               } 
  1762.               break;
  1763.       case 12:while(zeile<memheight)
  1764.               { zeile+=12;
  1765.                 for (i=0;i<(memwidth>>1);i+=12)
  1766.                 { n1=n2=0; j=i;
  1767.                   for (k=0;k<12;k++)
  1768.                   { n1+=((*(vptr+j   )>>4)+(*(vptr+j   )&15)+(*(vptr+j+ 1)>>4)+(*(vptr+j+ 1)&15)
  1769.                         +(*(vptr+j+ 2)>>4)+(*(vptr+j+ 2)&15)+(*(vptr+j+ 3)>>4)+(*(vptr+j+ 3)&15)
  1770.                         +(*(vptr+j+ 4)>>4)+(*(vptr+j+ 4)&15)+(*(vptr+j+ 5)>>4)+(*(vptr+j+ 5)&15));
  1771.                     n2+=((*(vptr+j+ 6)>>4)+(*(vptr+j+ 6)&15)+(*(vptr+j+ 7)>>4)+(*(vptr+j+ 7)&15)
  1772.                         +(*(vptr+j+ 8)>>4)+(*(vptr+j+ 8)&15)+(*(vptr+j+ 9)>>4)+(*(vptr+j+ 9)&15)
  1773.                         +(*(vptr+j+10)>>4)+(*(vptr+j+10)&15)+(*(vptr+j+11)>>4)+(*(vptr+j+11)&15));
  1774.                     j+=vinc;
  1775.                   }
  1776.                   linebuf[i/12]=(((n1/144)<<4)&0xf0)|((n2/144)&0x0f);
  1777.                 }
  1778.                 vplanesep(&linebuf[0],plptr[0],plptr[1],plptr[2],plptr[3],memwidth/96);
  1779.                 plptr[0]+=80; plptr[1]+=80; plptr[2]+=80; plptr[3]+=80;
  1780.                 vptr+=vicr[12];
  1781.               } 
  1782.               break;
  1783.     }
  1784.     else
  1785.     switch (sk)
  1786.     { case 4: while(zeile<memheight)
  1787.               { zeile+=4;
  1788.                 for (i=0;i<(memwidth>>3);i++)
  1789.                 { n1=numbits[(*(vptr+i        ))>>4]+numbits[(*(vptr+i+vicr[1]))>>4]
  1790.                     +numbits[(*(vptr+i+vicr[2]))>>4]+numbits[(*(vptr+i+vicr[3]))>>4];
  1791.                   if (n1==16) n1=15;
  1792.                   n2=numbits[(*(vptr+i        ))&15]+numbits[(*(vptr+i+vicr[1]))&15]
  1793.                     +numbits[(*(vptr+i+vicr[2]))&15]+numbits[(*(vptr+i+vicr[3]))&15];
  1794.                   if (n2==16) n2=15;
  1795.                   linebuf[i]=(~((n1<<4)|n2));
  1796.                 }
  1797.                 vplanesep(&linebuf[0],plptr[0],plptr[1],plptr[2],plptr[3],memwidth>>5);
  1798.                 plptr[0]+=80; plptr[1]+=80; plptr[2]+=80; plptr[3]+=80;
  1799.                 vptr+=vicr[4];
  1800.               } 
  1801.               break;
  1802.       case 8: while(zeile<memheight)
  1803.               { zeile+=8;
  1804.                 for (i=0;i<(memwidth>>3);i+=2)
  1805.                 { n1=(numbits[(*(vptr+i        ))]
  1806.                      +numbits[(*(vptr+i+vicr[1]))]
  1807.                      +numbits[(*(vptr+i+vicr[2]))]
  1808.                      +numbits[(*(vptr+i+vicr[3]))]
  1809.                      +numbits[(*(vptr+i+vicr[4]))]
  1810.                      +numbits[(*(vptr+i+vicr[5]))]
  1811.                      +numbits[(*(vptr+i+vicr[6]))]
  1812.                      +numbits[(*(vptr+i+vicr[7]))])>>2;
  1813.                   if (n1==16) n1=15;
  1814.                   n2=(numbits[(*(vptr+i+1        ))]
  1815.                      +numbits[(*(vptr+i+1+vicr[1]))]
  1816.                      +numbits[(*(vptr+i+1+vicr[2]))]
  1817.                      +numbits[(*(vptr+i+1+vicr[3]))]
  1818.                      +numbits[(*(vptr+i+1+vicr[4]))]
  1819.                      +numbits[(*(vptr+i+1+vicr[5]))]
  1820.                      +numbits[(*(vptr+i+1+vicr[6]))]
  1821.                      +numbits[(*(vptr+i+1+vicr[7]))])>>2;
  1822.                   if (n2==16) n2=15;
  1823.                   linebuf[i>>1]=(~((n1<<4)|n2));
  1824.                 }
  1825.                 vplanesep(&linebuf[0],plptr[0],plptr[1],plptr[2],plptr[3],memwidth>>6);
  1826.                 plptr[0]+=80; plptr[1]+=80; plptr[2]+=80; plptr[3]+=80;
  1827.                 vptr+=vicr[8];
  1828.               } 
  1829.               break;
  1830.       case 12:while(zeile<memheight)
  1831.               { zeile+=12;
  1832.                 for (i=0;i<(memwidth>>3);i+=3)
  1833.                 { n1=(numbits[(*(vptr+i           ))]
  1834.                      +numbits[(*(vptr+i+  vicr[ 1]))]
  1835.                      +numbits[(*(vptr+i+  vicr[ 2]))]
  1836.                      +numbits[(*(vptr+i+  vicr[ 3]))]
  1837.                      +numbits[(*(vptr+i+  vicr[ 4]))]
  1838.                      +numbits[(*(vptr+i+  vicr[ 5]))]
  1839.                      +numbits[(*(vptr+i+  vicr[ 6]))]
  1840.                      +numbits[(*(vptr+i+  vicr[ 7]))]
  1841.                      +numbits[(*(vptr+i+  vicr[ 8]))]
  1842.                      +numbits[(*(vptr+i+  vicr[ 9]))]
  1843.                      +numbits[(*(vptr+i+  vicr[10]))]
  1844.                      +numbits[(*(vptr+i+  vicr[11]))]
  1845.                      +numbits[(*(vptr+i+1         ))>>4]
  1846.                      +numbits[(*(vptr+i+1+vicr[ 1]))>>4]
  1847.                      +numbits[(*(vptr+i+1+vicr[ 2]))>>4]
  1848.                      +numbits[(*(vptr+i+1+vicr[ 3]))>>4]
  1849.                      +numbits[(*(vptr+i+1+vicr[ 4]))>>4]
  1850.                      +numbits[(*(vptr+i+1+vicr[ 5]))>>4]
  1851.                      +numbits[(*(vptr+i+1+vicr[ 6]))>>4]
  1852.                      +numbits[(*(vptr+i+1+vicr[ 7]))>>4]
  1853.                      +numbits[(*(vptr+i+1+vicr[ 8]))>>4]
  1854.                      +numbits[(*(vptr+i+1+vicr[ 9]))>>4]
  1855.                      +numbits[(*(vptr+i+1+vicr[10]))>>4]
  1856.                      +numbits[(*(vptr+i+1+vicr[11]))>>4]);
  1857.                   n2=(numbits[(*(vptr+i+2         ))]
  1858.                      +numbits[(*(vptr+i+2+vicr[ 1]))]
  1859.                      +numbits[(*(vptr+i+2+vicr[ 2]))]
  1860.                      +numbits[(*(vptr+i+2+vicr[ 3]))]
  1861.                      +numbits[(*(vptr+i+2+vicr[ 4]))]
  1862.                      +numbits[(*(vptr+i+2+vicr[ 5]))]
  1863.                      +numbits[(*(vptr+i+2+vicr[ 6]))]
  1864.                      +numbits[(*(vptr+i+2+vicr[ 7]))]
  1865.                      +numbits[(*(vptr+i+2+vicr[ 8]))]
  1866.                      +numbits[(*(vptr+i+2+vicr[ 9]))]
  1867.                      +numbits[(*(vptr+i+2+vicr[10]))]
  1868.                      +numbits[(*(vptr+i+2+vicr[11]))]
  1869.                      +numbits[(*(vptr+i+1         ))&15]
  1870.                      +numbits[(*(vptr+i+1+vicr[ 1]))&15]
  1871.                      +numbits[(*(vptr+i+1+vicr[ 2]))&15]
  1872.                      +numbits[(*(vptr+i+1+vicr[ 3]))&15]
  1873.                      +numbits[(*(vptr+i+1+vicr[ 4]))&15]
  1874.                      +numbits[(*(vptr+i+1+vicr[ 5]))&15]
  1875.                      +numbits[(*(vptr+i+1+vicr[ 6]))&15]
  1876.                      +numbits[(*(vptr+i+1+vicr[ 7]))&15]
  1877.                      +numbits[(*(vptr+i+1+vicr[ 8]))&15]
  1878.                      +numbits[(*(vptr+i+1+vicr[ 9]))&15]
  1879.                      +numbits[(*(vptr+i+1+vicr[10]))&15]
  1880.                      +numbits[(*(vptr+i+1+vicr[11]))&15]);
  1881.                   n1=n1/9;
  1882.                   n2=n2/9;
  1883.                   if (n1==16) n1=15;
  1884.                   if (n2==16) n2=15;
  1885.                   linebuf[i/3]=(~((n1<<4)|n2));
  1886.                 }
  1887.                 vplanesep(&linebuf[0],plptr[0],plptr[1],plptr[2],plptr[3],memwidth/96);
  1888.                 plptr[0]+=80; plptr[1]+=80; plptr[2]+=80; plptr[3]+=80;
  1889.                 vptr+=vicr[12];
  1890.               } 
  1891.               break;
  1892.     }    
  1893.   }
  1894.   else
  1895.   { vx=x&0xfff0; vy=y&0xfffe; sk=1;
  1896.     if (memgray) grayview(vptr,plptr[0],plptr[1],plptr[2],plptr[3],vinc); 
  1897.     else bwview(vptr,plptr[0],plptr[1],plptr[2],plptr[3],vinc); 
  1898.   } 
  1899. }
  1900.  
  1901. UWORD s2px(UWORD x)
  1902. { int t;
  1903.   t=x*sk+vx;
  1904.   if (t>=memwidth) t=memwidth-1;
  1905.   if (t<0) t=0;
  1906.   return((UWORD)t);
  1907. }
  1908.  
  1909. UWORD s2py(UWORD y)
  1910. { int t;
  1911.   t=y*sk+vy;
  1912.   if (t>=memheight) t=memheight-1;
  1913.   if (t<0) t=0;
  1914.   return((UWORD)t);
  1915. }
  1916.  
  1917. UWORD p2sx(UWORD x)
  1918. { int t;
  1919.   t=(x-vx)/sk;
  1920.   if (t>=624) t=623;
  1921.   if (t<0) t=0;
  1922.   return((UWORD)t);
  1923. }
  1924.  
  1925. UWORD p2sy(UWORD y)
  1926. { int t;
  1927.   t=(y-vy)/sk;
  1928.   if (t>=470) t=469;
  1929.   if (t<0) t=0;
  1930.   return((UWORD)t);
  1931. }
  1932.  
  1933. void drawbox()
  1934. { struct RastPort *wrp;
  1935.   int a,b,c,d;
  1936.   
  1937.   a=p2sx(wx1); b=p2sy(wy1)+10;
  1938.   c=p2sx(wx2); d=p2sy(wy2)+10; 
  1939.   { 
  1940.     wrp=win->RPort;
  1941.     SetWrMsk(wrp,8);
  1942.     SetAPen(wrp,8);
  1943.     SetDrMd(wrp,COMPLEMENT|JAM1);
  1944.     SetDrPt(wrp,0xcccc);
  1945.     Move(wrp,a,b);
  1946.     Draw(wrp,a,d);
  1947.     Draw(wrp,c,d);
  1948.     Draw(wrp,c,b);
  1949.     Draw(wrp,a,b);
  1950.     SetWrMsk(wrp,1);
  1951.     SetAPen(wrp,1);
  1952.     SetDrMd(wrp,COMPLEMENT|JAM1);
  1953.     SetDrPt(wrp,0x3333);
  1954.     Move(wrp,a,b);
  1955.     Draw(wrp,a,d);
  1956.     Draw(wrp,c,d);
  1957.     Draw(wrp,c,b);
  1958.     Draw(wrp,a,b);
  1959.     SetWrMsk(wrp,15);
  1960.   }
  1961. }
  1962.  
  1963. void save()
  1964. { int qdatei;
  1965.   ULONG totlen,bmlen;
  1966.   UWORD width,height,i,t;
  1967.   ULONG startofs;
  1968.   UBYTE *saveptr;
  1969.   UBYTE planes[4000];
  1970.   UBYTE sf;
  1971.  
  1972.   sf=(memgray)?1:3;
  1973.   if (mf==2)
  1974.   { if (wx1>wx2) {t=wx2; wx2=wx1; wx1=t;}
  1975.     if (wy1>wy2) {t=wy2; wy2=wy1; wy1=t;}
  1976.     width=(wx2-wx1);
  1977.     height=(wy2-wy1);
  1978.     startofs=wy1*(memwidth>>sf)+(wx1>>sf);
  1979.   }
  1980.   else 
  1981.   { width=memwidth;
  1982.     height=memheight;
  1983.     startofs=0;
  1984.   }
  1985.  
  1986.   filerequest("IFF File");
  1987.   qdatei=creat(str_filenam,1);
  1988.   bmlen=(memgray)?(width*height>>1):(width*height>>3);
  1989.   totlen=bmlen+40+((memgray)?56:14);
  1990.   iff_head[1]=totlen; 
  1991.   iff_head[5]=(width<<16)|height;
  1992.   iff_head[7]=(memgray)?0x04000000:0x01000000;
  1993.   iff_body[1]=bmlen;
  1994.   write(qdatei,&iff_head[0],sizeof(iff_head));
  1995.   if (memgray) write(qdatei,iff_cmap_gray,sizeof(iff_cmap_gray));
  1996.   else write(qdatei,iff_cmap_bw,sizeof(iff_cmap_bw));
  1997.   write(qdatei,iff_body,sizeof(iff_body));
  1998.   saveptr=memptr+startofs;
  1999.   if (memgray) for (i=0;i<height;i++)
  2000.   { fplanesep(saveptr,&planes[0],&planes[width>>3],&planes[2*(width>>3)],&planes[3*(width>>3)],(width>>3));
  2001.     write(qdatei,&planes[0],width>>1);
  2002.     saveptr+=(memwidth>>1);
  2003.   }
  2004.   else for (i=0;i<height;i++)
  2005.   { write(qdatei,saveptr,width>>3);
  2006.     saveptr+=(memwidth>>3);
  2007.   } 
  2008.   close(qdatei); 
  2009. }
  2010.  
  2011. void floyd()
  2012. { signed short lbuf[2][4000];
  2013.   UBYTE *grptr,*bwptr;
  2014.   USHORT i,j;
  2015.   signed short f,g;
  2016.   char wtitel[20];
  2017.  
  2018.   g=(signed short)(winpar.threshold/4);
  2019.   for (i=0;i<4000;i++) lbuf[0][i]=lbuf[1][i]=0;
  2020.   grptr=bwptr=memptr;
  2021.   for (i=0;i<memheight;i++)
  2022.   { for (j=0;j<memwidth;j++)
  2023.     { if (j&1) lbuf[0][j]=(signed short)(  (*(grptr+(j>>1)))     &15)+lbuf[1][j];
  2024.       else     lbuf[0][j]=(signed short)(( (*(grptr+(j>>1))) >>4)&15)+lbuf[1][j];
  2025.     }
  2026.     for (j=0;j<(memwidth>>3);j++) *(bwptr+j)=0;
  2027.     for (j=0;j<memwidth;j++)
  2028.     { if (lbuf[0][j]<g) 
  2029.       { f=lbuf[0][j];
  2030.         *(bwptr+(j>>3))|=bitval[j&7];
  2031.       }
  2032.       else f=lbuf[0][j]-15;
  2033.       lbuf[1][j]=(f+f+f)/8;
  2034.       lbuf[1][j+1]=f-2*lbuf[1][j];
  2035.       lbuf[0][j+1]+=((f+f+f)/8);
  2036.     }
  2037.     grptr+=(memwidth>>1);
  2038.     bwptr+=(memwidth>>3);
  2039.     if (!(i%100)) 
  2040.     { sprintf(&wtitel,"Dithering %03d %%",i*100/memheight);
  2041.       SetWindowTitles(win,&wtitel[0],(UBYTE *)-1);
  2042.     }
  2043.   }
  2044.   memneed=(memwidth*memheight)>>3;
  2045.   memgray=0;
  2046.   if (!(memptr=(UBYTE *)realloc(memptr,memneed)))
  2047.   { memneed=0;
  2048.     MessReq((UBYTE *)"Nicht mehr genug Speicher da!");
  2049.   }
  2050.   SetWindowTitles(win,NULL,(UBYTE *)-1);
  2051. }
  2052.  
  2053. void ordered()
  2054. { UBYTE *grptr,*bwptr;
  2055.   USHORT i,j;
  2056.   char wtitel[20];
  2057.   UBYTE refmat[4][4]={{0,7,2,9},{11,4,13,6},{3,10,1,8},{14,7,12,5}};
  2058.   UBYTE v;
  2059.  
  2060.   grptr=bwptr=memptr;
  2061.   for (i=0;i<memheight;i++)
  2062.   { for (j=0;j<memwidth;j++)
  2063.     { v=(j&1)?(  (*grptr)     &15)
  2064.              :(( (*grptr) >>4)&15);
  2065.       if (v>refmat[j&3][i&3]) *bwptr&=invbitval[j&7];
  2066.       else *bwptr|=bitval[j&7];
  2067.       if ((j&7)==7) bwptr++;
  2068.       if (j&1) grptr++;
  2069.     }
  2070.     if (!(i%100)) 
  2071.     { sprintf(&wtitel,"Dithering %03d %%",i*100/memheight);
  2072.       SetWindowTitles(win,&wtitel[0],(UBYTE *)-1);
  2073.     }
  2074.   }
  2075.   memneed=(memwidth*memheight)>>3;
  2076.   memgray=0;
  2077.   if (!(memptr=(UBYTE *)realloc(memptr,memneed)))
  2078.   { memneed=0;
  2079.     MessReq((UBYTE *)"Nicht mehr genug Speicher da!");
  2080.   }
  2081.   SetWindowTitles(win,NULL,(UBYTE *)-1);
  2082. }
  2083.  
  2084. void main()
  2085. {
  2086.     USHORT i; 
  2087.     USHORT nr;
  2088.     UWORD mx,my;
  2089.     
  2090.     if ((IntuitionBase = (struct IntuitionBase *)
  2091.          OpenLibrary("intuition.library",0L)) == 0L)
  2092.     {    ende();
  2093.          exit(100L);
  2094.     }
  2095.     if ((GfxBase = (struct GfxBase *)
  2096.          OpenLibrary("graphics.library",0L))==0L)
  2097.     {    ende();
  2098.          exit(100L);
  2099.     }
  2100.     if ((DosBase = (struct DosBase *)
  2101.          OpenLibrary("dos.library",0L))==0L)
  2102.     {    ende();
  2103.          exit(100L);
  2104.     } 
  2105.     if (!(imgptrf=AllocMem(sizeof(imagedataf),MEMF_CHIP)))
  2106.     {    ende();
  2107.          exit(85L);
  2108.     }
  2109.     if (!(imgptrz=AllocMem(sizeof(imagedataz),MEMF_CHIP)))
  2110.     {    ende();
  2111.          exit(85L);
  2112.     }
  2113.     memcpy(imgptrf,&imagedataf,sizeof(imagedataf));
  2114.     memcpy(imgptrz,&imagedataz,sizeof(imagedataz));
  2115.     fullimage.ImageData=(USHORT *)imgptrf;
  2116.     zoomimage.ImageData=(USHORT *)imgptrz;
  2117.     if (!(scr=(struct Screen*)OpenScreen(&ns)))
  2118.     {    ende();
  2119.          exit(90L);
  2120.     }
  2121.     vp=&scr->ViewPort;
  2122.     rp=&scr->RastPort;
  2123.     for (i=0;i<16;i++)
  2124.     { SetRGB4(vp,i,graystep[i],graystep[i],graystep[i]); }
  2125.     nw.Screen=scr;
  2126.     if (!(win=(struct Window *)OpenWindow(&nw)))
  2127.     {    ende();
  2128.          exit(90L);
  2129.     }
  2130.     if(!(diskport=CreatePort(0L,0L)))
  2131.     {    ende();
  2132.          exit(80L);
  2133.     }
  2134.     if(!(diskreq=(struct IOStdReq *)CreateStdIO(diskport)))
  2135.     {    ende();
  2136.          exit(80L);
  2137.     }
  2138.     if(openerror=OpenDevice(DEV_NAME,ST400ID,diskreq,0L))
  2139.     {    ende();
  2140.          exit(80L);
  2141.     }
  2142.   memptr=NULL; 
  2143.   mf=0;
  2144.   SetMenuStrip(win,&menu0);
  2145.   for (i=0;i<256;i++) numbits[i]=numbits_16[i/16]+numbits_16[i&15];
  2146.   for(;;)
  2147.   {
  2148.    Wait((long)(1L<<win->UserPort->mp_SigBit));
  2149.    while (Message=(struct IntuiMessage *)GetMsg(win->UserPort))
  2150.     {
  2151.       MessageClass=Message->Class;
  2152.       Code=Message->Code;
  2153.       ReplyMsg(Message);
  2154.       if (MessageClass==MENUPICK) menu(Code);
  2155.       if (((MessageClass==GADGETUP))&&(memneed))
  2156.       { if (!(Message->IAddress->GadgetID))
  2157.         { vprop.VertBody=(zgad.Flags&SELECTED)?0xffff:470*65536/memheight;
  2158.           hprop.HorizBody=(zgad.Flags&SELECTED)?0xffff:624*65536/memwidth;
  2159.           vprop.VertPot=0;
  2160.           hprop.HorizPot=0;
  2161.         }
  2162.         view(hprop.HorizPot*(memwidth-624)/65536,vprop.VertPot*(memheight-470)/65536,(zgad.Flags&SELECTED));
  2163.         if (mf==2) drawbox();
  2164.         RefreshGadgets(&vgad,win,NULL);
  2165.       }
  2166.       if ((MessageClass==MOUSEBUTTONS)&&(Code&128)&&(memneed))
  2167.       { mx=win->MouseX; my=win->MouseY;
  2168.         if ((mx<624)&&(my>=10)&&(my<470))
  2169.         switch(mf)
  2170.         { case 0: wx1=s2px(mx)&0xfff8; wy1=s2py(my-10); mf=1; break;
  2171.           case 1: wx2=s2px(mx)&0xfff8; wy2=s2py(my-10); mf=2; 
  2172.                   drawbox(); break;
  2173.           case 2: mf=0; drawbox(); break;
  2174.         }
  2175.       }
  2176.       if (MessageClass==CLOSEWINDOW)
  2177.       { ende();
  2178.         exit(0L);
  2179.       } /* if */
  2180.      } /* while */
  2181.    } /* for */
  2182. } /* main */
  2183.  
  2184. menu(Code)
  2185. USHORT Code;
  2186. {
  2187.   USHORT num,item,subitem;
  2188.   num=MENUNUM(Code);
  2189.   item=ITEMNUM(Code);
  2190.   subitem=SUBNUM(Code);
  2191.   switch(num)
  2192.   {  case 0: break;                    /* Info */
  2193.      case 1: switch(item)              /* Programm */
  2194.              { case 0: scan();         /* Einlesen */
  2195.                        vprop.VertBody=(zgad.Flags&SELECTED)?0xffff:470*65536/memheight;
  2196.                        hprop.HorizBody=(zgad.Flags&SELECTED)?0xffff:624*65536/memwidth;
  2197.                        vprop.VertPot=0;
  2198.                        hprop.HorizPot=0;
  2199.                        RefreshGadgets(&zgad,win,NULL);
  2200.                        if (memneed)
  2201.                        { view(0,0,(zgad.Flags&SELECTED));
  2202.                          mf=0;
  2203.                        }
  2204.                        break;
  2205.                case 1: save(); /* Speichern */
  2206.                        break;
  2207.                case 2: if ((memgray)&&(memneed))
  2208.                        { floyd(); /* Dither */
  2209.                          if (memneed) view(hprop.HorizPot*(memwidth-624)/65536,
  2210.                                            vprop.VertPot*(memheight-470)/65536,
  2211.                                            (zgad.Flags&SELECTED));
  2212.                          if (mf==2) drawbox();
  2213.                        }
  2214.                        break;
  2215.                case 3: if ((memgray)&&(memneed))
  2216.                        { ordered(); /* Dither */
  2217.                          if (memneed) view(hprop.HorizPot*(memwidth-624)/65536,
  2218.                                            vprop.VertPot*(memheight-470)/65536,
  2219.                                            (zgad.Flags&SELECTED));
  2220.                          if (mf==2) drawbox();
  2221.                        }
  2222.                        break;
  2223.                case 4: inquiry();
  2224.                        break;
  2225.                case 5: ende();         /* Ende */
  2226.                        exit(0L);
  2227.                        break;
  2228.                }
  2229.              break;
  2230.      case 2: winpar.resx=100*(item+2);
  2231.              winpar.resy=winpar.resx;
  2232.              break;
  2233.      case 3: winpar.size=5-item;
  2234.              break;
  2235.      case 4: winpar.halftone=item<<1;
  2236.              winpar.bitspixel=item ? 8 : 1;
  2237.              break;
  2238.      case 5: winpar.threshold=item<<2;
  2239.              break;
  2240.   }
  2241. }
  2242.  
  2243.  
  2244. ende() {
  2245.   if (memptr) free(memptr);
  2246.   if(openerror==0)
  2247.   { CloseDevice(diskreq);
  2248.   }
  2249.   if(diskport)DeletePort(diskport);
  2250.   if(diskreq)DeleteStdIO(diskreq);
  2251.   if (win) { ClearMenuStrip(win); CloseWindow(win); }
  2252.   if (scr) CloseScreen(scr); 
  2253.   if (imgptrf) FreeMem(imgptrf,sizeof(imagedataf));
  2254.   if (imgptrz) FreeMem(imgptrz,sizeof(imagedataz));
  2255.   if (DosBase) CloseLibrary(DosBase);
  2256.   if (GfxBase) CloseLibrary(GfxBase);
  2257.   if (IntuitionBase) CloseLibrary(IntuitionBase);
  2258. }
  2259.  
  2260.